﻿package mortal.game.view.common.guide.stepOperater
{
    import flash.events.*;
    import flash.utils.*;
    import mortal.common.net.*;
    import mortal.component.window.*;
    import mortal.game.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.view.common.guide.data.*;
    import mortal.mvc.core.*;

    public class AutoGuideTimerSteper extends AutoGuideStepBase implements IAutoGuideSteper
    {
        private var _timer:Timer;

        public function AutoGuideTimerSteper()
        {
            return;
        }// end function

        public function guide(param1:AutoGuideData, param2:Window = null) : void
        {
            if (this._timer != null)
            {
                return;
            }
            if (param1 == null || param1.guideType != AutoGuideType.Timer)
            {
                return;
            }
            Game.scene.mouseEnabled = false;
            _data = param1;
            this._timer = new Timer(int(param1.guideTypeValue), 1);
            this._timer.addEventListener(TimerEvent.TIMER_COMPLETE, this.timerCompleteHandler);
            this._timer.start();
            return;
        }// end function

        private function timerCompleteHandler(event:TimerEvent) : void
        {
            if (this._timer == null)
            {
                return;
            }
            Game.scene.mouseEnabled = true;
            this._timer.stop();
            this._timer = null;
            CallLater.addCallBack(this.nextFrame);
            return;
        }// end function

        private function nextFrame() : void
        {
            if (_data == null)
            {
                return;
            }
            this.stop(_data);
            return;
        }// end function

        override public function stop(param1:AutoGuideData = null) : void
        {
            super.stop(param1);
            if (param1 != null)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.AutoGuideStepEnd, param1));
            }
            return;
        }// end function

    }
}
